package daniel.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import daniel.taotao.common.pojo.itemListPojo;
import daniel.taotao.common.utils.TaotaoResult;
import daniel.taotao.pojo.TbItem;
import daniel.taotao.service.ItemService;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;

	@RequestMapping("/item/{itemId}")
	@ResponseBody
	public TbItem getItemById(@PathVariable Long itemId){
		TbItem item = itemService.getItemById(itemId);
		return item;
	}
	
	@RequestMapping("/")
	public String showIndex(){
		
		return "index";
	}
	
	@RequestMapping("/{page}")
	public String showPage(@PathVariable String page){
		
		return page;
	}
	
	@RequestMapping("/item/list")
	@ResponseBody
	public itemListPojo showPage(int page,int rows){
		itemListPojo listPage = itemService.getItemListPage(page, rows);
		return listPage;
	}
	
	@RequestMapping("/item/save")
	@ResponseBody
	public TaotaoResult showPageaddItem(TbItem item, String desc) {
		TaotaoResult taotaoResult = itemService.addItem(item, desc);
		return taotaoResult;
	}
}
